home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- * *
- * Copyright (c) 1992, 1993 Ronald Joe Record *
- * *
- * All rights reserved. No part of this program or publication may be *
- * reproduced, transmitted, transcribed, stored in a retrieval system, *
- * or translated into any language or computer language, in any form or *
- * by any means, electronic, mechanical, magnetic, optical, chemical, *
- * biological, or otherwise, without the prior written permission of: *
- * *
- * Ronald Joe Record (408) 458-3718 *
- * 212 Owen St., Santa Cruz, California 95062 USA *
- * *
- *************************************************************************/
-
- /*************************************************************************
- * *
- * Copyright (c) 1989 Hiram Clawson *
- * *
- * All rights reserved. No part of this program or publication may be *
- * reproduced, transmitted, transcribed, stored in a retrieval system, *
- * or translated into any language or computer language, in any form or *
- * by any means, electronic, mechanical, magnetic, optical, chemical, *
- * biological, or otherwise, without the prior written permission of: *
- * *
- * Hiram Clawson (408) 429-5647 *
- * P. O. Box 3178, Santa Cruz, California 95063-3178 USA *
- * *
- *************************************************************************/
- /*************************************************************************
- * rotate.c: Rotate a 3D point about an arbitrary axis defined *
- * by a vector *
- * *
- * Written by Hiram Clawson. *
- * Ported to X11 by Ronald Joe Record. *
- *************************************************************************/
- #include <math.h>
- #include "defines.h"
-
- void rotate (old_point, new_point, lambda, rotcos, rotsin, const1 )
- triple *old_point;
- triple *new_point;
- triple *lambda;
- double *rotcos;
- double *rotsin;
- double *const1;
- {
- register double f3;
- /*
- *
- * Rotate the point (oldx, oldy, oldz) about the axis defined by
- * the unit vector, lambda = (lambx, lamby, lambz)
- * by the angle whose cosine is rotcos and sine is rotsin,
- * with the extra constant const1, which is 1-rotcos.
- *
- * The rotation point is the origin: (0, 0, 0).
- * It is assumed that the point to rotate has been translated to
- * the origin. The reason I don't have an argument that would
- * be the point to rotate about is because I may want to do
- * several rotations on a translated point, before translating
- * it back to where it belongs.
- *
- * You can't have new_point be the same as old_point.
- * It will not work.
- *
- * The following three sets of calculations are essentially a
- * matrix multiply of the oldx,y,z by the rotation cosines giving
- * the *newx,y,z
- * f3 is a common factor to each calculation.
- */
- f3 = (*const1) * ( old_point->x * lambda->x
- + old_point->y * lambda->y
- + old_point->z * lambda->z );
-
- new_point->x = ( old_point->x * (*rotcos) )
- - (( (old_point->y * lambda->z )
- - ( old_point->z * lambda->y ) ) * (*rotsin) )
- + ( f3 * lambda->x );
-
- new_point->y = ( old_point->y * (*rotcos) )
- - (( (old_point->z * lambda->x )
- - ( old_point->x * lambda->z ) ) * (*rotsin) )
- + ( f3 * lambda->y );
-
- new_point->z = ( old_point->z * (*rotcos) )
- - (( (old_point->x * lambda->y )
- - ( old_point->y * lambda->x ) ) * (*rotsin) )
- + ( f3 * lambda->z );
-
- return;
- } /* end of rotate */
-